package com.czk.ssastructuredoutput.controller;

import com.czk.ssastructuredoutput.records.StudentRecord;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: chenzhangkun
 * @CreateTime: 2025-10-19
 * @Description:
 * @Version: 1.0
 */
@RestController
public class StructuredOutputController {
    @Resource(name = "qwenChatClient")
    private ChatClient qwenChatClient;

    /**
     * 结构化输出
     *
     * @param sname
     * @param email
     * @return
     */
    @GetMapping(value = "/structured-output/chat")
    public StudentRecord chat(@RequestParam(name = "sname", defaultValue = "张三") String sname,
                              @RequestParam(name = "email", defaultValue = "18") String email) {
        StudentRecord studentRecord = qwenChatClient.prompt()
                .user(p -> {
                    p.text("学号53，我叫{sname},大学专业计算机科学与技术，邮箱是{email}")
                            .param("sname", sname)
                            .param("email", email);
                }).call().entity(StudentRecord.class);
        return studentRecord;
    }

    @GetMapping(value = "/structured-output/chat2")
    public StudentRecord chat2(@RequestParam(name = "sname", defaultValue = "张三") String sname,
                               @RequestParam(name = "email", defaultValue = "18") String email) {

        String prompt = """
                学号53，我叫{sname},大学专业电子信息技术，邮箱是{email}
                """;

        return qwenChatClient.prompt()
                .user(p -> p.text(prompt))
                .call()
                .entity(StudentRecord.class);

    }
}
